class GoalsController < ApplicationController
  caches_page :index
  
  def index
    if params[:id].to_i > 0
      @goals = [ Goal.find(params[:id].to_i) ]
    else
      @goals = 
        Goal.get_items(Goal::ITEMS_PER_PAGE, params[:page])
      @goals_pages = 
        Goal.get_counts(Goal::ITEMS_PER_PAGE)
      @page = params[:page].to_i > 0 ? params[:page].to_i : 1
    end
    
    @goals.each do |goal|
      goal.goal_checkpoints.sort! { |x,y| x.targetted_at <=> y.targetted_at }
    end
    
    @completed_goals = 
      Goal.get_completed_items
  end
end
